package com.learn.game_card.service;

import com.learn.game_card.entity.role;
import java.util.Random;
import java.util.Scanner;

public class round {
    private role role1;
    private role role2;
    private String[] att1 = {"水", "火", "木"};
    private String[] flag1 = {"攻击", "防御"};

    public void roundGo(role role1, role role2) {
        System.out.println("\n回合开始！\nBoss当前生命值：" + role2.getHealth());
        System.out.println("你当前生命值：  " + role1.getHealth() + " 体力： " + role1.getPower());
        int flag;
        int att;
        Scanner scanner = new Scanner(System.in);
        if(role1.getPower()==0){
            System.out.println("你没有体力了，只能防御");
            flag = 2;
        }else {
            System.out.println("请选择你的动作(1攻击 2防御)");
            flag = scanner.nextInt();
        }
        System.out.println("请选择属性(1水 2火 3木)");
        att = scanner.nextInt();
        System.out.println("\nOK!你选择了" + att1[att - 1] + "属性的" + flag1[flag - 1]);

        Random random = new Random();
        int flag_boss = random.nextInt(2) + 1;
        int att_boss = random.nextInt(3) + 1;
        System.out.println("那么Boss选择了" + att1[att_boss - 1] + "属性的" + flag1[flag_boss - 1]);

        if (flag == 1 && flag_boss == 2) {
            if (isHave(att, att_boss)) {
                System.out.println("属性相克，你对boss造成了1点伤害");
                role2.setHealth(role2.getHealth() - 1);
                role1.setPower(role1.getPower() - 1);
                role2.setPower(role2.getPower() + 1);

            } else {
                System.out.println("你对boss造成了0点伤害");
                role1.setPower(role1.getPower() - 1);
                role2.setPower(role2.getPower() + 1);

            }
        }
        if (flag == 1 && flag_boss == 1) {
            if (isHave(att, att_boss)) {
                System.out.println("属性相克，你对boss造成了1点伤害");
                role2.setHealth(role2.getHealth() - 1);
                role1.setPower(role1.getPower() - 1);
                role2.setPower(role2.getPower() - 1);
            }
            if (isHave(att_boss, att)) {
                System.out.println("属性相克，boss对你造成了1点伤害");
                role1.setHealth(role1.getHealth() - 1); // 这里应该是 role1.setHealth(role1.getHealth() - 1);
                role1.setPower(role1.getPower() - 1);
                role2.setPower(role2.getPower() - 1);
            }
            if(att == att_boss){
                System.out.println("你和boss互相伤害");
                role1.setHealth(role1.getHealth() - 1);
                role2.setHealth(role2.getHealth() - 1);
                role1.setPower(role1.getPower() - 1);
                role2.setPower(role2.getPower() - 1);
            }
        }
        if (flag == 2 && flag_boss == 1) {
            if (isHave(att_boss, att)) {
                System.out.println("属性相克，boss对你造成了1点伤害");
                role1.setHealth(role1.getHealth() - 1);
                role1.setPower(role1.getPower() + 1);
                role2.setPower(role2.getPower() - 1);
            } else {
                System.out.println("boss对你造成了0点伤害");
                role1.setPower(role1.getPower() + 1);
                role2.setPower(role2.getPower() - 1);
            }
        }
        if (flag == 2 && flag_boss == 2){
            System.out.println("无事发生");
            role1.setPower(role1.getPower() + 1);
            role2.setPower(role2.getPower() + 1);
        }
    }

    public boolean isHave(int att, int att_boss) {
        return att_boss - att == 1 || att_boss - att == -2;
    }
}
